//
//  LZMyCollectionViewCell.m
//  laziz_Consumer
//
//  Created by ZhaoDongBo on 2016/10/26.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZMyCollectionViewCell.h"

#import "Masonry.h"
 

@implementation LZMyCollectionViewCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.contentView.backgroundColor = UIColorFromRGB(0xffffff, 1);
        self.redPointView.hidden = YES;
        [self configView];
        [self addAutoLayout];
    }
    return self;
}


#pragma mark - 对外方法
- (void)showRedPointView:(BOOL)show
{
    self.redPointView.hidden = !show;
}

/*
- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    if (self.indexPath.row % 2 == 1) {
        self.line1.hidden = NO;
    }
    else {
        self.line1.hidden = YES;
    }
    
    self.line1.hidden = NO;

    
    if (self.indexPath.row == 4 || self.indexPath.row == 5) {
        self.line2.hidden = YES;
    }
    else {
        self.line2.hidden = NO;
    }
    self.line2.hidden = NO;
}
 */

- (void)configView {

    [self.contentView addSubview:self.iconImageView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.line1];
    [self.contentView addSubview:self.line2];
    [self.contentView addSubview:self.redPointView];
}

- (void)addAutoLayout {
    
    [self.iconImageView makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(30);
        make.centerY.mas_equalTo(0);
    }];
    
    [self.redPointView makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(8, 8));
        make.leading.equalTo(self.iconImageView.mas_trailing).offset(-2);
        make.top.equalTo(self.iconImageView.top).offset(-3);
    }];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.iconImageView.mas_trailing).with.offset(15);
        make.centerY.mas_equalTo(0);
        make.trailing.mas_lessThanOrEqualTo(-10);
    }];
    
    [self.line1 makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.trailing.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.width.mas_equalTo(0.75);
    }];
    
    [self.line2 makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(0);
        make.trailing.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(0.75);
    }];
}

#pragma mark - Setter/Getter

- (UIImageView *)iconImageView {

    if (_iconImageView == nil) {
        _iconImageView = [[UIImageView alloc] init];
    }
    
    return _iconImageView;
}

- (UILabel *)titleLabel {

    if (_titleLabel == nil) {
        GET_SCREEN_SCALE(scale);
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor   = UIColorFromRGB(0x333333, 1);
        _titleLabel.font        = [UIFont systemFontOfSize:14*scale];
    }
    
    return _titleLabel;
}

- (UIView *)line1 {
    
    if (_line1 == nil) {
        _line1 = [[UIView alloc] init];
        _line1.backgroundColor = UIColorFromRGB(0xeeeeee, 1);
        _line1.hidden = NO;
    }
    
    return _line1;
}

- (UIView *)line2 {
    
    if (_line2 == nil) {
        _line2 = [[UIView alloc] init];
        _line2.backgroundColor = UIColorFromRGB(0xeeeeee, 1);
        _line2.hidden = NO;
    }
    
    return _line2;
}

- (UIView *)redPointView
{
    if (_redPointView) {
        return _redPointView;
    }
    
    _redPointView = [[UIView alloc] init];
    _redPointView.backgroundColor = [UIColor redColor];
    _redPointView.layer.cornerRadius = 4;
    _redPointView.layer.masksToBounds = YES;
    
    return _redPointView;
}
@end
